﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="WaitCursor.cs" company="Mar3ek">
//   http://mar3ek.wordpress.com
// </copyright>
// <summary>
//   Defines the WaitCursor type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Mar3ek.ColorHatTimeTracker
{
    using System;
    using System.Windows.Input;

    /// <summary>
    /// Implements the wait cursor mechanic.
    /// </summary>
    public class WaitCursor : IDisposable
    {
        /// <summary>
        /// The previous cursor.
        /// </summary>
        private readonly Cursor previousCursor;

        /// <summary>
        /// Initializes a new instance of the <see cref="WaitCursor"/> class.
        /// </summary>
        public WaitCursor()
        {
            this.previousCursor = Mouse.OverrideCursor;
            Mouse.OverrideCursor = Cursors.Wait;
        }

        #region IDisposable Members

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <param name="disposing">
        /// Whether to free managed resources.
        /// </param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                Mouse.OverrideCursor = this.previousCursor;
            }
        }

        #endregion
    }
}